package cn.niit.service.impl;

import cn.niit.dao.ResourceDao;
import cn.niit.entity.Resource;
import cn.niit.entity.query.ResourceQuery;
import cn.niit.service.ResourceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class ResourceServiceImpl implements ResourceService {
    @Autowired
    private ResourceDao resourceDao;


    @Override
    public List<Resource> list() {
        return resourceDao.list();
    }

    @Override
    public boolean add(Resource resource) {
        return resourceDao.add(resource)>0 ?  true : false;
    }

    @Override
    public PageInfo<Resource> listUserByName(ResourceQuery query) {
        PageHelper.startPage(query.getPageNum(), query.getPageSize());
        return new PageInfo<Resource>(resourceDao.listUserByName(query));
    }

    @Override
    public boolean updateResource(Resource resource) {
        int i = resourceDao.updateUser(resource);
        if (i > 0) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean deleteById(Integer id) {
        int i = resourceDao.deleteById(id);
        if(i > 0){
            return true;
        }else
        {
            return false;
        }
    }

    @Override
    public Resource queryResourceById(Integer id) {

        return  resourceDao.queryResourceById(id);
    }

    @Override
    public Resource findById(String id) {
        return resourceDao.findById(id);
    }
}
